using System;
using System.Drawing;
using System.Text;
using TTDotNet.Engine.ThreeDEngine;
using TTDotNet.Engine.GUI.Windows;
using Microsoft.DirectX.Direct3D;

namespace TTDotNet.Engine.GUI
{
    public class TitleBar : Label
    {
        private Window parentWindow;
        private int _xOffset;
        private int _yOffset;
        private bool downInRange;

        public TitleBar(RectangleF screenRect, string text, float fontSize, Color textColor, string fontName, GameTexture up, Window window ) 
                            : base(screenRect, text, fontSize, textColor, fontName, up, DrawTextFormat.Center | DrawTextFormat.VerticalCenter )
        {
            this.parentWindow = window;
        }

        protected override void OnMouseDown(Point cursor, bool[] buttons)
        {
            if (!downInRange)
            {
                if (Contains(cursor))
                {
                    downInRange = true;
                }
                else
                {
                    downInRange = false;
                }
            }

            if (downInRange)
            {
                _xOffset = cursor.X - _touchDownPoint.X;
                _yOffset = cursor.Y - _touchDownPoint.Y;
                parentWindow.MoveBy(_xOffset, _yOffset);
            }
        }

        protected override void OnMouseRelease(Point cursor)
        {
            downInRange = false;
        }
    }
}
